<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
    <@header title="角色管理" libs=["table"]/>
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <@f.form id="role-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                ${i18n("角色名称")}：<input type="text"  class="form-control" name="roleName"/>
                            </li>

                            <li>
                                ${i18n("权限字符")}：<input type="text" class="form-control" name="roleKey"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;${i18n("查询")}</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;${i18n("重置")}</a>
                            </li>
                        </ul>
                    </div>
                </@f.form>
            </div>
            <@table id="bootstrap-table">
                <@shiro.hasPermission name="sys:role:add">
                    <a class="btn btn-success" onclick="opt.operate.add()"><i class="fa fa-plus"></i>&nbsp;${i18n("新增")}</a>
                </@shiro.hasPermission>
                <@shiro.hasPermission name="sys:role:edit">
                    <a class="btn btn-primary single disabled" onclick="opt.operate.edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;${i18n("修改")}</a>
                </@shiro.hasPermission>
                <@shiro.hasPermission name="sys:role:del">
                    <a class="btn btn-danger multiple disabled" onclick="opt.operate.delAll()">
                        <i class="fa fa-remove"></i> ${i18n("删除")}
                    </a>
                </@shiro.hasPermission>
            </@table>
        </div>
    </div>
    <@footer>
        <script>
            var editFlag = "${permission.hasPermi('sys:role:edit')}";
            var delFlag = "${permission.hasPermi('sys:role:del')}";
            var dataFlag = "${permission.hasPermi('sys:role:data')}";
            var datas = ${dict.getDictListJson('sys_normal_disable')};
            var dataScope = ${dict.getDictListJson('sys_role_data_scope')};
            var visible = ${permission.isPermitteds("sys:role:edit,sys:role:del")?string('true', 'false')};
            var prefix = baseURL + 'sys/role';
            $(function() {
                /*初始表格对象*/
                var options = {
                    url: prefix + "/list",
                    addUrl: prefix + "/add",
                    editUrl: prefix + "/edit/{id}",
                    delUrl: prefix + "/del",
                    sortName: "createTime",
                    sortOrder: "asc",
                    rightFixedColumns: true,
                    rightFixedNumber: 2,
                    uniqueId: "id", /*唯一ID*/
                    modalName: "${i18n("角色")}",
                    columns: [
                        /*{title: "序号",width:10,align:"center", formatter: function (value, row, index) {
                                 return $.table.serialNumber(index);
                         }},
                         {checkbox: true},*/
                        {field: 'id',title: "${i18n("角色编码")}", sortable: true},
                        {field: 'roleName', title: "${i18n("角色名称")}"},
                        {field: 'roleKey', title: "${i18n("权限字符")}"},
                        {field: 'dataScope', title: "${i18n("数据范围")}", formatter: function(value, row, index) {
                                return opt.common.selectDictLabel(dataScope, value);
                            }},
                        {field: 'roleSort', title: "${i18n("顺序")}",sortable:true},
                        {field: 'status', title: "${i18n("状态")}", align: 'center', formatter: function(value, row, index) {
                                return opt.common.selectDictLabel(datas, value);
                            }},
                        {field: 'createTime', title: "${i18n("创建时间")}",sortable: true},
                        {title: "${i18n("操作")}", align: 'center',visible:visible, class:'action', formatter: function(value, row, index) {
                                /*var actions = [];
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="opt.operate.edit(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + delFlag + '" href="javascript:void(0)" onclick="opt.operate.del(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a>');
                                return actions.join('');*/
                                var actions = [];
                                actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="${i18n("修改")}" onclick="opt.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                                if(row.status === "0"){
                                    actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="${i18n("停用")}" onclick="disable(\'' + row.id + '\')"><i class="glyphicon glyphicon-ban-circle"></i></a> ');
                                }else{
                                    actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="${i18n("启用")}" onclick="enable(\'' + row.id + '\')"><i class="glyphicon glyphicon-ok-circle"></i></a> ');
                                }
                                actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="${i18n("删除")}" onclick="opt.operate.del(\'' + row.id + '\')"><i class="fa fa-trash-o"></i></a> ');
                                var info = "<a  class='btn btn-default btn-xs' onclick=javascript:authorization(\'" + row.id + "\');><i class='fa icon-check'></i> ${i18n("授权菜单")}</a>&nbsp;";

                                if(dataFlag != 'hidden'){
                                    info += "<a  class='btn btn-default btn-xs' onclick=javascript:authData(\'" + row.id + "\');><i class='fa fa-shield'></i> ${i18n("数据授权")}</a>&nbsp;";
                                }
                                info += "<a  class='btn btn-default btn-xs' onclick=javascript:authUser(\'" + row.id + "\');><i class='fa icon-user'></i> ${i18n("分配用户")}</a>&nbsp;";
                                actions.push('<a tabindex="0" class="' + delFlag + '" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="'+info+'"><i class="fa fa-chevron-circle-right"  title="${i18n("更多操作")}"></i></a>');
                                return actions.join('');
                            }}]
                };
                $.table.init(options);
            });

            /* 用户管理-停用 */
            function disable(roleId) {
                opt.modal.confirm("${i18n("确认要停用该角色吗?")}", function() {
                    opt.operate.post(prefix + "/changeStatus", { "id": roleId, "status": 1 });
                });
                return;
            }

            /* 用户管理启用 */
            function enable(roleId) {
                opt.modal.confirm("${i18n("确认要启用该角色吗?")}", function() {
                    opt.operate.post(prefix + "/changeStatus", { "id": roleId, "status": 0 });
                });
                return;
            }

            /*授权菜单*/
            function authorization(roleId) {
                opt.modal.open("${i18n("授权菜单")}", prefix + "/authorization/" + roleId,1100,500);
                return;
            }

            /*角色分配用户*/
            function authUser(roleId) {
                var url = prefix + '/authUser/' + roleId;
                opt.modal.openTab("${i18n("角色分配用户")}", url);
            }

            /*角色分配数据权限*/
            function authData(roleId){
                var url = prefix + '/authData/' + roleId;
                opt.modal.openTab("${i18n("角色分配数据权限")}", url);
            }
        </script>
    </@footer>
</@pageTheme>